
package com.ikkong.system.utils;

import com.ikkong.core.toolbox.Record;
import com.jfinal.json.FastJson;
import com.qiniu.util.StringMap;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;


public class CommonUtil {

    public static void main(String[] args) throws ParseException {
//		String ak ="rlL7b9rm3qc7HGQLozfeMjRq2KAFh7fqEVX-8BZd";
//		String sk="Hau3R6p5Dt4ve3xBun_-U2iAt8_h5p4-Y13ih_o6";
//		Auth auth = Auth.create(ak, sk);
//		System.out.println(auth);
//		String wanjia = auth.uploadToken("wanjia");
//		System.out.println(wanjia);
//		String s = auth.uploadToken("wanjia", ak, 3600, new StringMap().put("endUser", "uid").putNotEmpty("returnBody", ""));
//		System.out.println(s);


    }

    public void sendMsg() {
        String url = "http://127.0.0.1:8073/send";
        Map para = new HashMap();
        String str = URLEncoder.encode("#接龙\n" +
                "KTV报名\n" +
                "\n" +
                "1. 卖女孩的小火柴\n" +
                "2. NOSQL\n" +
                "3. NOSQL 家属");
//		String qun = "20671976800@chatroom";//群id
        para.put("msg", str);
        para.put("robot_wxid", "wxid_n4uoqwgaq03v22");
        para.put("to_wxid", "20671976800@chatroom");
        para.put("type", 100);
//		para.put("is_refresh",0);
//		para.put("group_wxid",qun);
        FastJson fj = new FastJson();
        String msg = fj.toJson(para);
        String data1 = fj.toJson(Record.create().set("data", msg));
        String parse = "";
        try {
            CloseableHttpClient httpClient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(url);
            httpPost.addHeader("Content-Type", "application/json");
            httpPost.setEntity(new StringEntity(data1));
            CloseableHttpResponse response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            parse = EntityUtils.toString(entity, "UTF-8");
            response.close();
            httpClient.close();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map parse2 = fj.parse(parse, Map.class);
//		String decode = URLDecoder.decode(parse2.get("data").toString());

//		Object parse1 = fj.parse(decode,List.class);
//
////		MembersRes parse1 = fj.parse(decode, MembersRes.class);
        System.out.println(parse2);

    }


//	public static String codeToDetail(String a_code){
//		String parse = "";
//		try {
//			HttpClient httpclient = new DefaultHttpClient();
//			String uri = "https://cft.nsl.api.bbitcn.net:8000/api/v1/system/jianpiao?code="+a_code;
//			HttpGet httppost = new HttpGet(uri);
//			httppost.addHeader("Authorization","Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjFDOTE2MDJGMDE5ODkyMEQwMjg2MTIzOTk2RjQ4NzI0NUZBRTM4NEIiLCJ0eXAiOiJKV1QiLCJ4NXQiOiJISkZnTHdHWWtnMENoaEk1bHZTSEpGLXVPRXMifQ.eyJuYmYiOjE2MDEwMzIxODIsImV4cCI6MTYwMzYyNDE4MiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwIiwiYXVkIjpbImh0dHA6Ly9sb2NhbGhvc3Q6NTAwMC9yZXNvdXJjZXMiLCJhcGkiXSwiY2xpZW50X2lkIjoicHdkQ2xpZW50Iiwic3ViIjoiMTc3NjUzNzEwMDUiLCJhdXRoX3RpbWUiOjE2MDEwMzIxODIsImlkcCI6ImxvY2FsIiwidXNlcnN5c2lkIjoiRDE4N0U4NjgtM0ZFNC00OERFLUI4NzItQjhBNThEN0E0MDA2IiwidXNlcnR5cGUiOiIyIiwic2NvcGUiOlsiYXBpIl0sImFtciI6WyJjdXN0b20iXX0.FwoRYN78bFUF3XRGGhyuFpT9c3wNNeGZ8qnolwT5IpoNFR-JIicX1VXFSYAeYNm6rWIA6-mDBkEN6HE-BXkC472WcUPgk8diRgRmZ-95kjUDjCdLiePeng07a1u3eOzBCAQZNsnTnJm3vsoNNJZ7aSu0nLDleIQKDFoR_aawASYQ6cgHrp7Y9qFqRp1tCbHb4C80fAS_vhb_cCW_K7C6U5AHBRDC-8wz6UqPQzFLS0KzsM1OtjXWUcmdsFOWz98grUlb0Cr0i4KMthsGjbDuLqLzqS4wErU4Quois6Cj4oz6TRslA89b56EIaAFd3o3k9Ig7Ik16F6egDEJN218AbQ");
//			HttpResponse response = httpclient.execute(httppost);
//			//检验状态码，如果成功接收数据
//			int code = response.getStatusLine().getStatusCode();
//			System.out.println(code+"code");
//			if (code == 200) {
//				parse = EntityUtils.toString(response.getEntity());//返回json格式： {"id": "","name": ""}
//			}
//		} catch (ClientProtocolException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return parse;
//	}
}
